Skip to content

configuration: make AbsolutePath a wrapper type#15362

Open
amaanq wants to merge 1 commit intoNixOS:masterfrom
obsidiansystems:convert-path-setting-followup
Open

configuration: make AbsolutePath a wrapper type#15362
amaanq wants to merge 1 commit intoNixOS:masterfrom
obsidiansystems:convert-path-setting-followup

Conversation

@amaanq
Copy link
Member

@amaanq amaanq commented Feb 27, 2026

Motivation

Public inheritance from std::filesystem::path lets AbsolutePath
silently slice down to a plain path when passed by value, so this commit changes
AbsolutePath to use a path field instead, which is easier to reason about and prevents that.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

* rejecting empty and relative paths.
*/
struct AbsolutePath : std::filesystem::path
struct AbsolutePath
Copy link
Contributor

@xokdvium xokdvium Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be done using private inheritance, no? Less churny code to write, just using path::operator== and stuff.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm I tried this, and it looks like we'd still have churn because we can't just do using path::operator== and friends because they are defined as non-member friend functions

@amaanq amaanq force-pushed the convert-path-setting-followup branch from 906aabb to 029f54c Compare February 28, 2026 05:14
@amaanq amaanq force-pushed the convert-path-setting-followup branch from 029f54c to 7de2b59 Compare March 8, 2026 00:02
@amaanq amaanq requested a review from xokdvium March 8, 2026 00:02
Public inheritance from `std::filesystem::path` lets `AbsolutePath`
silently slice down to a plain path when passed by value, so this commit changes
`AbsolutePath` to use a `path` field instead, which is easier to reason about and prevents that.
@amaanq amaanq force-pushed the convert-path-setting-followup branch from 7de2b59 to 125d6f3 Compare March 8, 2026 00:28

if (auto & caFile = fileTransfer.settings.caFile.get())
curl_easy_setopt(req, CURLOPT_CAINFO, caFile->c_str());
curl_easy_setopt(req, CURLOPT_CAINFO, caFile->string().c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you double-check the docs for curl wrt to lifetime requirements on these temporaries? I think it copies some arguments, so this might be fine, but worth double-checking.

/* If no file exist in the specified path, curl continues to work
anyway as if netrc support was disabled. */
curl_easy_setopt(req, CURLOPT_NETRC_FILE, fileTransfer.settings.netrcFile.get().c_str());
curl_easy_setopt(req, CURLOPT_NETRC_FILE, fileTransfer.settings.netrcFile.get().string().c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

{
using path::path;
using path::operator=;
std::filesystem::path path;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this private? With just an accessor? This will help ensure the invariant.

Comment on lines +229 to +237
AbsolutePath(std::filesystem::path p)
: path(std::move(p))
{
}

AbsolutePath(std::filesystem::path && p)
: path(std::move(p))
AbsolutePath(const char * s)
: path(s)
{
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructors should then barf if the path is not absolute, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants